package com.sasis.model;

public class UserFunctionPermission extends BaseEntity implements Permission {

	private static final long serialVersionUID = 1L;
	
	private Long userId;
	
	private Long functionId;
	
	private boolean allow;
	
	public UserFunctionPermission() {
		
	}
	
	public UserFunctionPermission(Long userId, Long functionId, boolean allow) {
		this.userId = userId;
		this.functionId = functionId;
		this.allow = allow;
	}
	
	public UserFunctionPermission(Permission permission) {
		this.userId = permission.getPrincipal().getId();
		this.functionId = permission.getSubject().getId();
		this.allow = permission.isAllow();
	}
	
	public Long getFunctionId() {
		return functionId;
	}

	public void setFunctionId(Long functionId) {
		this.functionId = functionId;
	}

	public Long getUserId() {
		return userId;
	}

	public void setUserId(Long userId) {
		this.userId = userId;
	}

	public boolean isAllow() {
		return allow;
	}

	public void setAllow(boolean allow) {
		this.allow = allow;
	}
	
	public Principal getPrincipal() {
		return new BasePrincipal(userId, false);
	}

	public Subject getSubject() {
		return new BaseSubject(functionId, true);
	}
}
